﻿/*
This file is under Microsoft Public License (MS-PL)
Copyright Yohann MARTEL.  All rights reserved.
Codeplex: http://amf.codeplex.com
AMF Website: http://www.ymartel.com/aspnet-mobile-framework/
*/
using System;
using System.ComponentModel;
using System.Web.UI;

namespace Mobile.WebControls
{
    public class ButtonGroup : Div
    {
        #region Properties
        [Browsable(false), DefaultValue(null), PersistenceMode(PersistenceMode.InnerProperty),
         TemplateContainer(typeof(SimpleTemplate))]
        public ITemplate Content { get; set; }

        [Category("Appearance")]
        public DataType DataType { get; set; }

        public override ControlCollection Controls
        {
            get
            {
                EnsureChildControls();
                return base.Controls;
            }
        }
        #endregion

        #region Methods
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            if (Content != null)
            {
                SimpleTemplate contentContainer = new SimpleTemplate();
                Content.InstantiateIn(contentContainer);
                Controls.Add(contentContainer);
            }

        }
        #endregion

        #region Render Methods
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            writer.AddAttribute(MetadataAttribute.DataRole, DataRole.ControlGroup);
            if (DataType != DataType.Default)
            {
                writer.AddAttribute(MetadataAttribute.DataType, Enum.GetName(typeof(DataType), DataType).ToLower());
            }

        }
        #endregion
    }
}
